//
//  CZEmoticonPackageModel.swift
//  keyBoard
//
//  Created by 李伟鹏 on 16/5/22.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CZEmoticonPackageModel: NSObject {
    
    var id: String
    var group_name_cn: String
    var emoticons: [CZEmoticonModel]
    var pageEmotions: [[CZEmoticonModel]] = [[CZEmoticonModel]]()
    
    init(id: String, group_name_cn: String, emoticons: [CZEmoticonModel]){
        self.id = id
        self.group_name_cn = group_name_cn
        self.emoticons = emoticons
        super.init()
        spliteEmoticons()
    }
    
    private func spliteEmoticons(){
        let pageCount = (emoticons.count + CZEmoticonNumberOfPage - 1) / CZEmoticonNumberOfPage
        
        if pageCount == 0{
            let emptyPageEmoticon = [CZEmoticonModel]()
            pageEmotions.append(emptyPageEmoticon)
            return
        }
        
        for i in 0..<pageCount{
            let location = i * CZEmoticonNumberOfPage
            var length = CZEmoticonNumberOfPage
            if location + CZEmoticonNumberOfPage > emoticons.count{
                length = emoticons.count - location
            }
            let range = NSRange(location: location, length: length)
            let pageEmotion = (emoticons as NSArray).subarrayWithRange(range) as! [CZEmoticonModel]
            pageEmotions.append(pageEmotion)
        }
    }
    
    override var description: String {
        get {
            return "\n \t 表情包模型: id: \(id), group_name_cn: \(group_name_cn), emoticons: \(emoticons)"
        }
    }
}
